// 小测验
; (function () {
    return
    var times = [0, 0, 0, 0, 0];

    for (var i = 0; i < 100000; i++) {

        let arr = [1, 2, 3, 4, 5];

        arr.sort(() => Math.random() - 0.5);

        times[arr[4] - 1]++;

    }

    console.log(times) //[ 25072, 7064, 21065, 18712, 28087 ]
    // 可以看出2出现在末尾的次数最少

})();

// 插叙源码
; (function () {
    return
    function InsertionSort(a, from, to) {
        for (var i = from + 1; i < to; i++) {
            var element = a[i];
            for (var j = i - 1; j >= from; j--) {
                var tmp = a[j];
                var order = tmp-element;
                if (order > 0) {
                    a[j + 1] = tmp;
                } else {
                    break;
                }
            }
            a[j + 1] = element;
        }
    };

})();

; (function () {
    //return

    var times = 100000;
    var res = {};

    for (var i = 0; i < times; i++) {

        var arr = [1, 2,3];
        arr.sort(() => Math.random() - 0.5);

        var key = JSON.stringify(arr);
        res[key] ? res[key]++ : res[key] = 1;
    }

    // 为了方便展示，转换成百分比
    for (var key in res) {
        res[key] = res[key] / times * 100 + '%'
    }

    console.log(res)
    // '[1,2,3]': '37.391999999999996%'
    // '[1,3,2]': '6.228%'
    // '[2,1,3]': '12.456%'
    // '[2,3,1]': '6.2829999999999995%'
    // '[3,1,2]': '6.1850000000000005%'
    // '[3,2,1]': '31.456%'
    

})();